home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / parseconfig.inc < prev    next >
Encoding:
Text File  |  2005-01-06  |  7.9 KB  |  370 lines

  1. ;; $Id: parseconfig.inc,v 1.21 2005/01/06 22:34:06 hpa Exp $
  2. ;; -----------------------------------------------------------------------
  3. ;;   
  4. ;;   Copyright 1994-2004 H. Peter Anvin - All Rights Reserved
  5. ;;
  6. ;;   This program is free software; you can redistribute it and/or modify
  7. ;;   it under the terms of the GNU General Public License as published by
  8. ;;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  9. ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
  10. ;;   (at your option) any later version; incorporated herein by reference.
  11. ;;
  12. ;; -----------------------------------------------------------------------
  13.  
  14. ;;
  15. ;; parseconfig.inc
  16. ;;
  17. ;; Configuration file operations
  18. ;;
  19.  
  20.         section .text
  21. ;
  22. ; "default" command
  23. pc_default:    mov di,default_cmd
  24.         call getline
  25.         mov byte [di-1],0        ; null-terminate
  26.         ret
  27.  
  28. ;
  29. ; "ontimeout" command
  30. ;
  31. pc_ontimeout:    mov di,Ontimeout
  32.         call getline
  33.         sub di,Ontimeout+1        ; Don't need final space
  34.         mov [OntimeoutLen],di
  35.         ret
  36.  
  37. ;
  38. ; "onerror" command
  39. ;
  40. pc_onerror:    mov di,Onerror
  41.         call getline
  42.         sub di,Onerror
  43.         mov [OnerrorLen],di
  44.         ret
  45.  
  46. ;
  47. ; "append" command
  48. ;
  49. pc_append:      cmp byte [VKernel],0
  50.         ja .vk
  51.                 mov di,AppendBuf
  52.         call getline
  53.                 sub di,AppendBuf
  54. .app1:            mov [AppendLen],di
  55.         ret
  56. .vk:        mov di,VKernelBuf+vk_append    ; "append" command (vkernel)
  57.         call getline
  58.         sub di,VKernelBuf+vk_append
  59.                 cmp di,byte 2
  60.                 jne .app2
  61.                 cmp byte [VKernelBuf+vk_append],'-'
  62.                 jne .app2
  63.                 xor di,di            ; If "append -" -> null string
  64. .app2:        mov [VKernelBuf+vk_appendlen],di
  65.         ret
  66.  
  67. ;
  68. ; "ipappend" command (PXELINUX only)
  69. ;
  70. %if IS_PXELINUX
  71. pc_ipappend:    call getint
  72.         jc .err
  73.         cmp byte [VKernel],0
  74.         jne .vk
  75.         mov [IPAppend],bl
  76. .err:        ret
  77. .vk:        mov [VKernelBuf+vk_ipappend],bl
  78.         ret
  79. %endif
  80.  
  81. ;
  82. ; "localboot" command (PXELINUX, ISOLINUX)
  83. ;
  84. %if IS_PXELINUX || IS_ISOLINUX
  85. pc_localboot:    call getint
  86.         cmp byte [VKernel],0        ; ("label" section only)
  87.         je .err
  88.         mov di,VKernelBuf+vk_rname
  89.         xor ax,ax
  90.         mov cx,FILENAME_MAX
  91.         rep stosb            ; Null kernel name
  92. %if IS_PXELINUX
  93.         ; PXELINUX uses the first 4 bytes of vk_rname for the
  94.         ; mangled IP address
  95.         mov [VKernelBuf+vk_rname+5], bx    ; Return type
  96. %else
  97.         mov [VKernelBuf+vk_rname+1], bx    ; Return type
  98. %endif
  99. .err:        ret
  100. %endif
  101.  
  102. ;
  103. ; "kernel" command
  104. pc_kernel:    cmp byte [VKernel],0
  105.         je .err                ; ("label" section only)
  106.         call pc_getline
  107.         mov di,VKernelBuf+vk_rname
  108.         call mangle_name
  109. .err:        ret
  110.  
  111. ;
  112. ; "timeout" command
  113. ;
  114. pc_timeout:    call getint
  115.         jc .err
  116.         mov ax,0D215h            ; There are approx 1.D215h
  117.         mul bx                ; clock ticks per 1/10 s
  118.         add bx,dx
  119.         mov [KbdTimeOut],bx
  120. .err:        ret
  121.  
  122. ;
  123. ; Generic integer variable setting commands:
  124. ; "prompt", "implicit"
  125. ;
  126. pc_setint16:
  127.         push ax
  128.         call getint
  129.         pop si
  130.         jc .err
  131.         mov [si],bx
  132. .err:        ret
  133.  
  134. ;
  135. ; Generic file-processing commands:
  136. ; "display", "font", "kbdmap"
  137. ;
  138. pc_filecmd:    push ax                ; Function to tailcall
  139.         call pc_getline
  140.         mov di,MNameBuf
  141.         push di
  142.         call mangle_name
  143.         pop di
  144.         call searchdir            ; tailcall
  145.         jnz .ok
  146.         pop ax                ; Drop the successor function
  147. .ok:        ret                ; Tailcall if OK, error return
  148.  
  149. ;
  150. ; "serial" command
  151. ;
  152. pc_serial:    call getint
  153.         jc .err
  154.         push bx                ; Serial port #
  155.         call skipspace
  156.         jnc .ok
  157.         pop bx
  158. .err:        ret
  159. .ok:
  160.         call ungetc
  161.         call getint
  162.         mov [FlowControl], word 0    ; Default to no flow control
  163.         jc .nobaud
  164. .valid_baud:    
  165.         push ebx
  166.         call skipspace
  167.         jc .no_flow
  168.         call ungetc
  169.         call getint            ; Hardware flow control?
  170.         jnc .valid_flow
  171. .no_flow:
  172.         xor bx,bx            ; Default -> no flow control
  173. .valid_flow:
  174.         and bh,0Fh            ; FlowIgnore
  175.         shl bh,4
  176.         mov [FlowIgnore],bh
  177.         mov bh,bl
  178.         and bx,0F003h            ; Valid bits
  179.         mov [FlowControl],bx
  180.         pop ebx                ; Baud rate
  181.         jmp short .parse_baud
  182. .nobaud:
  183.         mov ebx,DEFAULT_BAUD        ; No baud rate given
  184. .parse_baud:
  185.         pop di                ; Serial port #
  186.         cmp ebx,byte 75
  187.         jb .err                ; < 75 baud == bogus
  188.         mov eax,BAUD_DIVISOR
  189.         cdq
  190.         div ebx
  191.         mov [BaudDivisor],ax
  192.         push ax                ; Baud rate divisor
  193.         cmp di,3
  194.         ja .port_is_io            ; If port > 3 then port is I/O addr
  195.         shl di,1
  196.         mov di,[di+serial_base]        ; Get the I/O port from the BIOS
  197. .port_is_io:
  198.         mov [SerialPort],di
  199.         lea dx,[di+3]            ; DX -> LCR
  200.         mov al,83h            ; Enable DLAB
  201.         call slow_out
  202.         pop ax                ; Divisor
  203.         mov dx,di            ; DX -> LS
  204.         call slow_out
  205.         inc dx                ; DX -> MS
  206.         mov al,ah
  207.         call slow_out
  208.         mov al,03h            ; Disable DLAB
  209.         add dx,byte 2            ; DX -> LCR
  210.         call slow_out
  211.         in al,dx            ; Read back LCR (detect missing hw)
  212.         cmp al,03h            ; If nothing here we'll read 00 or FF
  213.         jne .serial_port_bad        ; Assume serial port busted
  214.         sub dx,byte 2            ; DX -> IER
  215.         xor al,al            ; IRQ disable
  216.         call slow_out
  217.  
  218.         add dx,byte 3            ; DX -> MCR
  219.         in al,dx
  220.         or al,[FlowOutput]        ; Assert bits
  221.         call slow_out
  222.  
  223.         ; Show some life
  224.         mov si,syslinux_banner
  225.         call write_serial_str
  226.         mov si,copyright_str
  227.         call write_serial_str
  228.         ret
  229.  
  230. .serial_port_bad:
  231.         mov [SerialPort], word 0
  232.         ret
  233.  
  234. ;
  235. ; "F"-key command
  236. ;
  237. pc_fkey:    push ax
  238.         call pc_getline
  239.         pop di
  240.         call mangle_name        ; Mangle file name
  241.         ret
  242.  
  243. ;
  244. ; "label" command
  245. ;
  246. pc_label:    call commit_vk            ; Commit any current vkernel
  247.         mov di,VKernelBuf        ; Erase the vkernelbuf for better compression
  248.         mov cx,(vk_size >> 1)
  249.         xor ax,ax
  250.         rep stosw
  251.         call pc_getline
  252.         mov di,VKernelBuf+vk_vname
  253.         call mangle_name        ; Mangle virtual name
  254.         mov byte [VKernel],1        ; We've seen a "label" statement
  255.         mov si,VKernelBuf+vk_vname     ; By default, rname == vname
  256.         mov di,VKernelBuf+vk_rname
  257.         mov cx,FILENAME_MAX
  258.         rep movsb
  259.                 mov si,AppendBuf             ; Default append==global append
  260.                 mov di,VKernelBuf+vk_append
  261.                 mov cx,[AppendLen]
  262.                 mov [VKernelBuf+vk_appendlen],cx
  263.                 rep movsb
  264. %if IS_PXELINUX                    ; PXELINUX only
  265.         mov al,[IPAppend]        ; Default ipappend==global ipappend
  266.         mov [VKernelBuf+vk_ipappend],al
  267. %endif
  268.         ret
  269.  
  270. ;
  271. ; "say" command
  272. ;
  273. pc_say:        call pc_getline            ; "say" command
  274.         call writestr
  275.         jmp crlf            ; tailcall
  276.  
  277. ;
  278. ; "noescape" command
  279. ;
  280. pc_noescape:
  281.         mov byte [KbdFlags],0
  282.         ; Fall into pc_getline
  283.  
  284. ;
  285. ; Comment line
  286. ;
  287. pc_comment:    ; Fall into pc_getline
  288.  
  289. ;
  290. ; Common subroutine: load line into trackbuf; returns with SI -> trackbuf
  291. ;
  292. pc_getline:    mov di,trackbuf
  293.         push di
  294.         call getline
  295.         xor al,al
  296.         stosb                ; Null-terminate
  297.         pop si
  298.         ret
  299.  
  300. ;
  301. ; Main loop for configuration file parsing
  302. ;
  303. parse_config:
  304.         call getcommand
  305.                 jnc parse_config        ; If not EOF do it again
  306.         ;
  307.         ; The fall through to commit_vk to commit any final
  308.         ; VKernel being read
  309.         ;
  310. ;
  311. ; commit_vk: Store the current VKernelBuf into buffer segment
  312. ;
  313. commit_vk:
  314.         ; For better compression, clean up the append field
  315.         mov ax,[VKernelBuf+vk_appendlen]
  316.         mov di,VKernelBuf+vk_append
  317.         add di,ax
  318.         mov cx,max_cmd_len+1
  319.         sub cx,ax
  320.         xor ax,ax
  321.         rep stosb
  322.  
  323.         ; Pack temporarily into trackbuf
  324.         mov si,VKernelBuf
  325.         mov di,trackbuf
  326.         mov cx,vk_size
  327.         call rllpack
  328.         ; Now DX = number of bytes
  329.         mov di,[VKernelBytes]
  330.         mov cx,dx
  331.         add dx,di
  332.         jc .overflow            ; If > 1 segment
  333.         mov [VKernelBytes],dx
  334.         mov si,trackbuf
  335.         push es
  336.         push word vk_seg
  337.         pop es
  338.         rep movsb
  339.         pop es
  340.         ret
  341. .overflow:
  342.         mov si,vk_overflow_msg
  343.         call writestr
  344.         ret
  345.  
  346.         section .data
  347. vk_overflow_msg    db 'Out of memory parsing config file', CR, LF, 0
  348.  
  349.         align 2, db 0
  350. AppendLen       dw 0                    ; Bytes in append= command
  351. OntimeoutLen    dw 0            ; Bytes in ontimeout command
  352. OnerrorLen    dw 0            ; Bytes in onerror command
  353. KbdTimeOut      dw 0                    ; Keyboard timeout (if any)
  354. CmdLinePtr    dw cmd_line_here    ; Command line advancing pointer
  355. ForcePrompt    dw 0            ; Force prompt
  356. AllowImplicit   dw 1                    ; Allow implicit kernels
  357. AllowOptions    dw 1            ; User-specified options allowed
  358. SerialPort    dw 0            ; Serial port base (or 0 for no serial port)
  359. VKernelBytes    dw 0            ; Number of bytes used by vkernels
  360. VKernel        db 0            ; Have we seen any "label" statements?
  361.  
  362.         section .bss
  363.                 alignb 4        ; For the good of REP MOVSD
  364. command_line    resb max_cmd_len+2    ; Command line buffer
  365.         alignb 4
  366. default_cmd    resb max_cmd_len+1    ; "default" command line
  367.  
  368. %include "rllpack.inc"
  369.